#include "vga.h"
#include "system.h"
#include "io.h"
#include <stdio.h>

void Vga::locate_cursor( const int& x, const int& y )
{
    unsigned int command = 0;
    
    // build command
    command = ( x ) + ( y << 10 );
    
    // send the command to the VGA memory-mapped I/O address
    IOWR_32DIRECT( VGA_BASE, ADDRESS_OFFSET_MOVE_CURSOR, command );
}

void Vga::move_cursor( const int& dir_x, const int& dir_y )
{
    // apply location
    m_cursor_pos_x += dir_x;
    m_cursor_pos_y += dir_y;
    
    // check whether the direction exceeds the corner location
    if( m_cursor_pos_x < 0 )
    {
        m_cursor_pos_x = 0;
    }
    else if( m_cursor_pos_x > m_width )
    {
        m_cursor_pos_x = m_width;
    }
    
    if( m_cursor_pos_y < 0 )
    {
        m_cursor_pos_y = 0;
    }
    else if( m_cursor_pos_y > m_height )
    {
        m_cursor_pos_y = m_height;
    }
    
    // send the command
    locate_cursor( m_cursor_pos_x, m_cursor_pos_y );
}

void Vga::set_resolution( const int& width, const int& height )
{
    m_width = width;
    m_height = height;
}

void Vga::store_image( const int& image_id, const unsigned short * buf, const int& len )
{
}

void Vga::mount_image( const int& sprite_id, const int& image_id )
{
}